package com.ls.code01;

/**
 * @author LS
 * @version 1.0
 * @description: 选择排序
 * @date 2021/5/3 下午12:07
 */
public class Code02 {
    public static void print(int[] array) {
        if (array == null || array.length < 2) {
            return;
        }
        for (int i = 0; i < array.length; i++) {
            int minValueIndex = i;
            for (int j = i + 1; j < array.length; j++) {
                minValueIndex = array[minValueIndex] < array[j] ? minValueIndex : j;
            }
            swap(array, i, minValueIndex);
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;

    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 2, 5, 1, 6, 4, 7, 5};
        print(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
